//二分查找简单表达
public class BinarySearch {
    public static void main(String[] args) {
        int[] array = {1, 5, 8, 11, 19, 22, 31, 35, 40, 45, 56, 58, 60};
        int target = 45;
        int idx = binarySearch(array, target);
        System.out.println(idx);

    }

    public static int binarySearch(int[] array, int target) {
        int l = 0, r = array.length - 1, m;
        while (l <= r) {
            m = (r + l) / 2;
            if (array[m] == target) {
                return m;
            } else if (array[m] > target) {
                r = m - 1;
            } else {
                l = m + 1;
            }

        }
        return -1;
    }
}
